** Construct domestic input and export shares, and material shares

gen si = foreignmaterial / materials
gen xi = exportshare / 100
bys year: egen totalmat=total(materials)
gen mi = materials / totalmat
gen misi  = mi * si
label var si "Import Share"

* Exporter dummy 
gen exporter = 0
replace exporter = 1 if exportshare>0

* Create product indicator
gen prod2=int(mainproduct/1000)
rename prod2 sector

* Assign product code from 1998 to 1999 and 2000 (product code is missing for these two years)
gen sectorb = 0
replace sectorb = sector if year==1998
bys id: egen sectorc = total(sectorb)
replace sectorc = . if sectorc==0
replace sector= sectorc if year==1999 | year==2000
drop sectorc
